$(document).ready(function(){


    var scheduleid=0;
 try{
    scheduleid=localStorage.getItem("scheduleid")
 }
 catch(error){
    scheduleid=0;
 }

 if(scheduleid>0)
 {
$(".firstclass").empty();     
$(".businessclass").empty();   
$(".economyclass").empty();   
    $.ajax({
        type:"POST",
        url:"./DetailServlet",
        data:"scheduleid="+scheduleid,
        success:function(json){
            var msg=JSON.parse(json);
            if(msg!=null&&msg.flag=="success")
            {
                var sch=msg.infoList[0].listsch[0];                          
                $(".info").text(sch.DepartureAirportIATA+" to "+sch.ArrivalAirportIATA+","+sch.date+","+sch.Name);        
                if(sch.Name!="Boeing 737-800")
                {
                    $(".flightimg img").attr("src","./image/319.jpg");
                }
                var a=0;
                var b=0;
                var c=0;
                var tick=msg.infoList[0].listtick;
                for(var i=0;i<tick.length;i++)
                {
                    if(tick[i].CabinTypeId==3)
                    {
                        a=tick[i].counts;
                    }
                    if(tick[i].CabinTypeId==2)
                    {
                        b=tick[i].counts;
                    }
                    if(tick[i].CabinTypeId==1)
                    {
                        c=tick[i].counts;
                    }
                }
                $(".ticketmsg").children().eq(0).children().eq(1).text(a+"/"+sch.FirstSeatsAmount+" "+Math.floor(a/sch.FirstSeatsAmount*100)+" %");
                $(".ticketmsg").children().eq(0).children().eq(2).text("Total Tickets:"+sch.FirstSeatsAmount);
                $(".ticketmsg").children().eq(0).children().eq(3).text("Sold Tickets:"+a);
                $(".ticketmsg").children().eq(0).children().eq(4).text("Seats Selected:"+a);

                $(".ticketmsg").children().eq(1).children().eq(1).text(b+"/"+sch.BusinessSeatsAmount+" "+Math.floor(b/sch.BusinessSeatsAmount*100)+" %");
                $(".ticketmsg").children().eq(1).children().eq(2).text("Total Tickets:"+sch.BusinessSeatsAmount);
                $(".ticketmsg").children().eq(1).children().eq(3).text("Sold Tickets:"+b);
                $(".ticketmsg").children().eq(1).children().eq(4).text("Seats Selected:"+b);

                $(".ticketmsg").children().eq(2).children().eq(1).text(c+"/"+sch.EconomySeatsAmount+" "+Math.floor(a/sch.EconomySeatsAmount*100)+" %");
                $(".ticketmsg").children().eq(2).children().eq(2).text("Total Tickets:"+sch.EconomySeatsAmount);
                $(".ticketmsg").children().eq(2).children().eq(3).text("Sold Tickets:"+c);
                $(".ticketmsg").children().eq(2).children().eq(4).text("Seats Selected:"+c);
            }

           var firstntml="";
           var  busntml="";
           var econontml="";

           var arr1=msg.infoList[0].seat;
           var arr=msg.infoList[0].seatlout;
            for(var i=0;i<arr.length;i++)
            {
                if(arr[i].CabinTypeId==3)
                {
                    firstntml+=` <div class="seatstyle" data-name="${arr[i].RowNumber}${arr[i].ColumnName}">${arr[i].RowNumber}${arr[i].ColumnName}</div>`;
                }

                if(arr[i].CabinTypeId==2)
                {
                    busntml+=` <div class="busseat" data-name="${arr[i].RowNumber}${arr[i].ColumnName}">${arr[i].RowNumber}${arr[i].ColumnName}</div>`;
                }
                if(arr[i].CabinTypeId==1)
                {
                    econontml+=` <div class="busseat" data-name="${arr[i].RowNumber}${arr[i].ColumnName}">${arr[i].RowNumber}${arr[i].ColumnName}</div>`;
                }
            }
            $(".firstclass")[0].innerHTML=firstntml;
            $(".businessclass")[0].innerHTML=busntml;
            $(".economyclass")[0].innerHTML=econontml;

            for(var i=0;i<arr1.length;i++)
            {
                if(arr1[i].CabinTypeId==3)
                {
                    $(".firstclass div:contains('"+arr1[i].RowNumber+arr1[i].ColumnName+"')").css("background-color","orange");
                }
                if(arr1[i].CabinTypeId==2)
                {
                    $(".businessclass div:contains('"+arr1[i].RowNumber+arr1[i].ColumnName+"')").css("background-color","orange");
                }
                if(arr1[i].CabinTypeId==1)
                {
                    $(".economyclass div:contains('"+arr1[i].RowNumber+arr1[i].ColumnName+"')").css("background-color","orange");
                }
            }
          
        }
    });
 }

 
 



});